<?php

namespace App\Http\Controllers;

use App\Http\Model\Hint;
use App\Http\Model\OutJson;
use App\Http\Services\MaximumGoldServices;
use Illuminate\Http\Request;

class MaximumGoldController extends BaseController
{
    /**
     * @var Request
     */
    protected $request;

    /**
     * @var MaximumGoldServices
     */
    protected $service;

    /**
     * @var int[]
     */
    protected $charts_type = [1, 2, 3];// 榜单类型

    /**
     * @param MaximumGoldServices $service
     * @param Request $request
     */
    public function __construct(MaximumGoldServices $service, Request $request)
    {
        $this->service = $service;
        $this->request = $request;
    }

    /**
     * 最多金-人气榜
     *
     * Created at 2021/12/13 11:12
     * @Author <yuxiang.zhu@asiainnovations.net>
     */
    public function charmCharts()
    {
        $type = (int)$this->request->get('type'); //1:日 2：周 3：总
        if (!$type || !in_array($type, $this->charts_type)) {
            OutJson::outJsonResult(Hint::PARAM_ERROR, []);
        }

        $page = !empty((int)$this->request->get('page_index')) && $this->request->get('page_index') >= 0 ? (int)$this->request->get('page_index') : 0;
        $page_size = !empty((int)$this->request->get('page_size')) && $this->request->get('page_size') > 0 ? (int)$this->request->get('page_size') : 10;
        $result = $this->service->getCharmCharts($type, $page, $page_size);
        OutJson::outJsonResult(Hint::SUCCESS, $result);
    }

    /**
     * 最多金-富豪榜
     *
     * Created at 2021/12/13 11:46
     * @Author <yuxiang.zhu@asiainnovations.net>
     */
    public function wealthCharts()
    {
        $type = (int)$this->request->get('type'); //1:日 2：周 3：总
        if (!$type || !in_array($type, $this->charts_type)) {
            OutJson::outJsonResult(Hint::PARAM_ERROR, []);
        }

        $page = !empty((int)$this->request->get('page_index')) && $this->request->get('page_index') >= 0 ? (int)$this->request->get('page_index') : 0;
        $page_size = !empty((int)$this->request->get('page_size')) && $this->request->get('page_size') > 0 ? (int)$this->request->get('page_size') : 10;
        $result = $this->service->getWealthCharts($type, $page, $page_size);
        OutJson::outJsonResult(Hint::SUCCESS, $result);
    }

    /**
     * 最多金-房间榜
     *
     * Created at 2021/12/13 11:48
     * @Author <yuxiang.zhu@asiainnovations.net>
     */
    public function roomWealthCharts()
    {
        $type = (int)$this->request->get('type'); //1:日 2：周 3：总
        if (!$type || !in_array($type, $this->charts_type)) {
            OutJson::outJsonResult(Hint::PARAM_ERROR, []);
        }

        $page = !empty((int)$this->request->get('page_index')) && $this->request->get('page_index') >= 0 ? (int)$this->request->get('page_index') : 0;
        $page_size = !empty((int)$this->request->get('page_size')) && $this->request->get('page_size') > 0 ? (int)$this->request->get('page_size') : 10;
        $result = $this->service->getRoomSelfWealthCharts($type, $page, $page_size);
        OutJson::outJsonResult(Hint::SUCCESS, $result);
    }
}